import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:p_location/common/constant/color_list.dart';
import 'package:p_location/home/res/home_tab_area_detail_obj.dart';
import 'package:p_location/home/ui/page_tab_area_info.dart';
import 'package:p_location/utils/navigator_util.dart';
import 'package:p_location/utils/string_util.dart';

class HomeTabAreaItemWidget extends StatelessWidget {
  final HomeTabAreaDetailObj obj;
  final Function onClick;

  HomeTabAreaItemWidget(this.obj, this.onClick);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
//        if (mode == ClickType.selectMode) {
//          Navigator.of(context).pop(obj);
//          this.obj.isExpand = !this.obj.isExpand;
        print('sfsgwererw${obj.nodeId}');
        NavigatorUtil.push(context, PageTabAreaInfo(obj.nodeId, obj.areaName));
//        this.onClick();
//        } else {
//          NavigatorUtil.push(context, DeptInfoDetailPage(obj.id.toString()));
//        }
      },
      child: Container(
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(10))),
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.fromLTRB(10, 15, 10, 15),
          child: Flex(
            direction: Axis.horizontal,
            children: <Widget>[
              Expanded(
                  flex: 2,
                  child: Container(
                    margin:EdgeInsets.only(left: (obj.level - 1) * 20.0),
                    //left: (obj.level > 1 ? obj.level : 2 - 2) * 20.0),
                    child: Text(
                      StringUtil.getEliminateString(obj.areaName, 17),
                      style: TextStyle(
                        color: Color.fromARGB(255, 26, 103, 250),
                        fontSize: 14,
                      ),
                    ),
                  )),
              Expanded(
                  flex: 1,
                  child: Container(
//                    color: Colors.red,
                    alignment: Alignment.center,
                    child: Text("${obj.personCount}"),
                  )),
              Expanded(
                  flex: 2,
                  child: Stack(
                    children: [
                      Container(
                        alignment: Alignment.center,
                        child: Text("${obj.carCount}"),
                      ),
                      Positioned(
                          right: 5,
                          child: GestureDetector(
                            onTap:(){
                              this.onClick();
                            },
                            child: Container(
                              child: obj.child != null && obj.child.length > 0 ? Icon(
                                (obj.isExpand
                                    ? Icons.keyboard_arrow_up
                                    : Icons.keyboard_arrow_down),
                                color: ColorList.BLACK_45,
                              ):Text(""),
                            ),
                          ))
                    ],
                  ))
            ],
          ),
        ),
      ),
    );
  }
}
